﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Bilylib;

public partial class sitemanagement_Faq : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["Username"] == null)
            {
                Response.Redirect("HTLogin.aspx");
            }

            BindFAQ();
        }
    }

    private void BindFAQ()
    {
        try
        {
            DataTable tbFAQ = new DataTable();
            string sql = "Select FAQID, FullName, Title, Email, Question, LEFT(Answer, 80) AS Answer, CONVERT(VARCHAR(10), DateQuestion, 101) AS DateQuestion From FAQ Where QuestionStatus = @QuestionStatus And Status = @Status";
            Select select = Select.newInstance();
            select.SetConnectionName("HoangThinhDataConnectionString");
            select.SetValues(0);
            select.SetValues(1);
            tbFAQ = select.SelectCustomParam(sql);
            gvFAQ.DataSource = tbFAQ;
            gvFAQ.DataBind();
        }
        catch { }
    }

    protected void ddlCate_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlCate.SelectedValue == "1")
        {
            DataTable tbFAQ = new DataTable();
            string sql = "Select FAQID, FullName, Title, Email, Question, LEFT(Answer, 80) AS Answer, CONVERT(VARCHAR(10), DateQuestion, 101) AS DateQuestion From FAQ Where QuestionStatus = @QuestionStatus And Status = @Status";
            Select select = Select.newInstance();
            select.SetConnectionName("HoangThinhDataConnectionString");
            select.SetValues(0);
            select.SetValues(1);
            tbFAQ = select.SelectCustomParam(sql);
            gvFAQ.DataSource = tbFAQ;
            gvFAQ.DataBind();
        }
        else
        {
            DataTable tbFAQ = new DataTable();
            string sql = "Select FAQID, FullName, Title, Email, Question, LEFT(Answer, 80) AS Answer, CONVERT(VARCHAR(10), DateQuestion, 101) AS DateQuestion From FAQ Where QuestionStatus = @QuestionStatus And Status = @Status";
            Select select = Select.newInstance();
            select.SetConnectionName("HoangThinhDataConnectionString");
            select.SetValues(1);
            select.SetValues(1);
            tbFAQ = select.SelectCustomParam(sql);
            gvFAQ.DataSource = tbFAQ;
            gvFAQ.DataBind();
        }
    }
}